package com.jic.market.controller.manage;

import com.jic.common.base.vo.RestResult;
import com.jic.market.api.manage.SecSkillManageApi;
import com.jic.market.request.AddSeckillRequest;
import com.jic.market.request.PromotionRequest;
import com.jic.market.request.SeckillListRequest;
import com.jic.market.response.AddSeckillResponse;
import com.jic.market.response.PageResponse;
import com.jic.market.response.PromotionResponse;
import com.jic.market.response.SeckillListResponse;
import com.jic.market.service.JicMarketPromotionService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 *
 * Created by xuyongliang on 2020/1/9.
 */

@RestController
@RequestMapping("/seckill")
public class SeckillManageController implements SecSkillManageApi {

    private final static Logger logger = LoggerFactory.getLogger(SeckillManageController.class);

    @Resource
    private JicMarketPromotionService promotionService;

    @PostMapping("/list")
    @ResponseBody
    @Override
    public RestResult<PageResponse<PromotionResponse>> secSkillList(@RequestBody SeckillListRequest request) {

        logger.info("==========={}",request);
        PromotionRequest proReq =new PromotionRequest();
        proReq.setPromName(request.getPromName());
        proReq.setId(request.getPromId());
        proReq.setFrontPromType(request.getFrontPromType());

        promotionService.listByPage(proReq);

        return null;
    }


    @ResponseBody
    @RequestMapping(value = "/hi" ,method = RequestMethod.POST)
    public void hello(@RequestParam("name") String name) {
        System.out.println("---------"+name);
    }

    @Override
    public RestResult<AddSeckillResponse> doAddSeckill(AddSeckillRequest request) {

        PromotionRequest promRequest =new PromotionRequest();
        BeanUtils.copyProperties(request,promRequest);

        promotionService.addPromotion(promRequest);
        return null;
    }

}
